package demo.practice.leetcode_eveyday;

import java.util.*;

public class P198 {

    /**
     * 打家劫舍  此解法错误
     */


    public static void main(String[] args) {
        P198 p198 = new P198();
        p198.rob(new int[]{1, 2});
    }

    public int rob(int[] nums) {

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            list.add(i);
        }
        Collections.sort(list, (i, i2) -> -nums[i] + nums[i2]);
        Set<Integer> neighbors = new HashSet<>();
        int sum = 0;

        //
        for (int i = 0; i < list.size(); i++) {
            if (!neighbors.contains( list.get(i) )) {
                sum += nums[list.get(i)];
                neighbors.add(list.get(i) + 1);
                neighbors.add(list.get(i) - 1);
            }
        }
        return sum;
    }


}
